#include"cpp-httplib/httplib.h"      
#include"searcher.hpp"      
#include"log.hpp"

const std::string input="./data/raw_html/raw.txt";      
      
const std::string root_path="./wwwroot";      
      
int main()      
{      
  ns_searcher::Searcher searcher;  
  searcher.InitSearcher(input);  
  
  httplib::Server s;  
  s.set_base_dir(root_path.c_str());  
  s.Get("/s",[&searcher](const httplib::Request& req,httplib::Response& res)                                                                                               
      {                                           
    if(!req.has_param("word")){  
      res.set_content(" 必须要有关键字 ","text/plain; charset=utf-8");      
      return;                  
      }                        
      std::string word=req.get_param_value("word");          
       LOG(NORMAL,"用户搜索的关键词为:"+word);
     // std::cout<<"用户搜索的关键词为:"<<word<<std::endl;          
      std::string json_string;          
      searcher.Search(word,&json_string);          
      res.set_content(json_string,"application/json");           
       });           
  LOG(NORMAL,"服务器启动成功...");
  s.listen("0.0.0.0",8081);      
    return 0;                  
}  
